package net.qunzhi.modules.cms.controller;

import java.util.Arrays;
import java.util.List;

import net.qunzhi.common.utils.BaseQuery;
import net.qunzhi.common.annotation.SysLog;
import net.qunzhi.modules.cms.vo.DataResultVO;
import net.qunzhi.modules.cms.vo.MonitorVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import net.qunzhi.modules.cms.entity.TbAlarmMonitorEntity;
import net.qunzhi.modules.cms.service.TbAlarmMonitorService;
import net.qunzhi.common.utils.PageUtils;
import net.qunzhi.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 监控报警信息
 *
 * @author zjr
 * @date 2021-11-02 09:38:29
 */
@Api(tags = "监控报警信息相关")
@RestController
@RequestMapping("cms/tbAlarmMonitor")
public class TbAlarmMonitorController {
    @Autowired
    private TbAlarmMonitorService tbAlarmMonitorService;

    /**
     * 列表
     */
//    @ApiOperation("列表")
//    @GetMapping("/list")
//    @RequiresPermissions("cms:tbAlarmMonitor:list")
//    public R list(BaseQuery query){
//        PageUtils page = tbAlarmMonitorService.queryPage(query);
//
//        return R.ok().put("page", page);
//    }

    @ApiOperation("监控报警")
    @GetMapping("/monitor")
    @RequiresPermissions("cms:tbAlarmMonitor:list")
    public R monitor(){
        List<MonitorVO> vo = tbAlarmMonitorService.queryMonitorList();

        return R.ok().put("vo", vo);
    }


    @ApiOperation("测试监控报警定时")
    @GetMapping("/test")
    public R test(){
        tbAlarmMonitorService.doAlarmMonitorTask();

        return R.ok();
    }

    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TbAlarmMonitorEntity tbAlarmMonitor = tbAlarmMonitorService.getById(id);

        return R.ok().put("tbAlarmMonitor", tbAlarmMonitor);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @SysLog("监控报警信息保存")
    @PostMapping("/save")
    @RequiresPermissions("cms:tbAlarmMonitor:save")
    public R save(@RequestBody TbAlarmMonitorEntity tbAlarmMonitor){
		tbAlarmMonitorService.save(tbAlarmMonitor);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @SysLog("监控报警信息修改")
    @PostMapping("/update")
    @RequiresPermissions("cms:tbAlarmMonitor:update")
    public R update(@RequestBody TbAlarmMonitorEntity tbAlarmMonitor){
		tbAlarmMonitorService.updateById(tbAlarmMonitor);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @SysLog("监控报警信息删除")
    @PostMapping("/delete")
    @RequiresPermissions("cms:tbAlarmMonitor:delete")
    public R delete(@RequestBody Integer[] ids){
		tbAlarmMonitorService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
